<template>
  <div class="app-container-flex">
    <NewFullScreen
      v-model="showDialog"
      :title="title"
      :btnList="fullInfo.btnList"
    >
      <template v-slot:full-button>
        <el-button
          v-if="
            $permission('contract:confirm') &&
            infoList.data.checkStatus === 1 &&
            infoList.data.orgId != orgId
          "
          :plain="true"
          @click="confirm"
          >确认</el-button
        >
        <el-button
          v-if="
            $permission('contract:refuse') &&
            infoList.data.checkStatus === 1 &&
            infoList.data.orgId != orgId
          "
          :plain="true"
          @click="refuse"
          >拒绝</el-button
        >
      </template>

      <div class="model-panel">
        <div class="model-panel-title">
          <p>{{ $t('basic_information') }}</p>
        </div>
        <div class="model-panel-body">
          <basic-information :info="infoList">
            <template v-slot:basic-brandLicenseFilePath>
              <span>
                <ele-gallery
                  :lazy="true"
                  :size="150"
                  :source="infoList.data.brandLicenseFilePathList"
                  title="资质"
                ></ele-gallery>
              </span>
            </template>
          </basic-information>
        </div>
      </div>
    </NewFullScreen>
  </div>
</template>

<script setup name="pendCheckContractDetail">
import BasicInformation from '@/components/BasicInformation/index'
import EleGallery from '@/components/UploadImg/eleGallery'
import { getContractPage, contractConfirm, contractRefuse } from '@/api/core'

import { getContract } from '@/api/core'

const { proxy } = getCurrentInstance()
const emit = defineEmits()
const props = defineProps(['visible', 'id'])

// 过滤相关配置
const orgId = ref(proxy.$store.state.user.userInfo.user.orgId)
const title = ref('合同详情')
const infoList = reactive({
  data: {},
  fieldList: [
    { label: '合同甲方', value: 'partyA' },
    { label: '合同乙方', value: 'partyBName' },
    { label: '合同名称', value: 'name' },
    { label: '合同编号', value: 'code' },
    {
      label: '合同金额',
      value: 'sum',
      formatter: proxy.$fn.TripartiteMethod,
    },
    { label: '签订日期', value: 'signDate' },
    { label: '生效日期', value: 'effectiveDate' },
    { label: '失效日期', value: 'expirationDate' },
    // { label: "保修到期", value: "warrantyDate" },
    { label: '经办人', value: 'operateUser' },
    // { label: "合同位置", value: "contractSite" },
    // { label: "合同类型", value: "contractTypeValue" },
    { label: '合同附件', value: 'contractAnnexPathList', type: 'slot' },
    { label: '备注', value: 'remark', type: 'popover' },
  ],
})
const fullInfo = reactive({
  btnList: [{ value: 'button', type: 'slot' }],
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})

watch(
  () => props.visible,
  (newVal) => {
    showDialog.value = newVal
  },
  {
    immediate: true,
  }
)

onMounted(() => {
  init()
})

//确认
function confirm() {
  const ids = [infoList.data.id]
  contractConfirm(ids).then((resp) => {
    if (resp && resp.success) {
      init()
    }
  })
}
//拒绝
function refuse() {
  const ids = [infoList.data.id]
  contractRefuse(ids).then((resp) => {
    if (resp && resp.success) {
      init()
    }
  })
}
function init() {
  getContract(props.id).then((res) => {
    if (res) {
      infoList.data = res.data
    }
  })
}
</script>

<style scoped></style>
